csrc = $(wildcard src/*.c)
ccsrc = $(wildcard src/*.cc)
obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)

lib_a = libvmath.a
lib_so = libvmath.so

CC = gcc
CXX = g++
CFLAGS = -std=c89 -pedantic -Wall -g -fpic -Isrc
CXXFLAGS = -ansi -pedantic -Wall -g -fpic -Isrc
LDFLAGS =

.PHONY: all
all: $(lib_a) $(lib_so)

$(lib_a): $(obj)
	$(AR) rcs $@ $^

$(lib_so): $(obj)
	$(CXX) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS)

.PHONY: install
install: $(lib_a) $(lib_so)
	install -d $(PREFIX)/lib
	install -m 644 $(lib_a) $(lib_so) $(PREFIX)/lib
	install -d $(PREFIX)/include/vmath
	install -m 644 src/*.h src/*.inl $(PREFIX)/include/vmath
	install -d $(PREFIX)/lib/pkgconfig
	install -m 644 vmath.pc $(PREFIX)/lib/pkgconfig

.PHONY: uninstall
uninstall:
	rm -f $(PREFIX)/lib/$(lib_a)
	rm -f $(PREFIX)/lib/$(lib_so)
	rm -f $(PREFIX)/include/vmath/*
	rmdir $(PREFIX)/include/vmath
	rm -f $(PREFIX)/lib/pkgconfig/vmath.pc

.PHONY: clean
clean:
	rm -f $(obj)

.PHONY: distclean
distclean:
	rm -f $(obj) $(lib_so) $(lib_a) Makefile vmath.pc

.PHONY: dist
dist: distclean
	cd ..; tar czvf vmath.tar.gz vmath && mv vmath.tar.gz vmath/
